function tab=tableDraws(drawsMat,percentiles,names)
[Ndraws,Ncols]=size(drawsMat); 

if isempty(percentiles)==true 
    percentiles=[0.001 0.01 0.05 0.1 0.5 0.9 0.95 0.99 0.999];
    
end 
Nper=length(percentiles);

posExtract=round(Ndraws*percentiles); 

tabTop=cell(4,Ncols+1); 
tabTop(1:4,1)={'Name';'Median';'Mean';'Std'}; 
tabBottom=cell(Nper,Ncols+1); 

for ii=1:Ncols; 
    xsim=sort(drawsMat(:,ii));
    tabTop(1,ii+1)={ names{ii} }; 
    tabTop(2,ii+1)={ sprintf('%3.4f',median(xsim) )}; 
    tabTop(3,ii+1)={ sprintf('%3.4f',mean(  xsim) )}; 
    tabTop(4,ii+1)={ sprintf('%3.4f',std(  xsim) )}; 
    for jj=1:Nper;
        if ii==1 
            tabBottom(jj,1)={ sprintf('%1.3f',percentiles(jj)) } ; 
        end 
        tabBottom(jj,ii+1)={ sprintf('%3.4f',xsim( posExtract(jj)) ) } ;
    end
end     
tab=[tabTop;tabBottom]; 
